<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><%=UserUtil.getCurrentMenuItemName() %></title>
    
    <script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
    
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {          
        $("[id^='viewPayerImg-']").click(function() {
            var payerTempPk = this.id.substring(13);
            doQueryPayerTempAction(payerTempPk);            
        });
        
        $("[id^='passPayerBtn']").click(function() {
        	doPayersConfirmAction('Y');
    	});
    	$("[id^='cancelPayerBtn']").click(function() {
    		doPayersConfirmAction('N');
    	});
        
        $("#checkAll").click(function() {
    		doCheckAll();
    	});
    	$("#unCheckAll").click(function() {
    		undoCheckAll();
    	});
    	
    });
    
    function doQueryPayerTempAction(payerTempPk)
    {
        $('#hidden\\.payerTempPk').val(payerTempPk);

        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez2001.action'/>",
            async : true,
            type : 'POST',
            data : $("#queryPayerTempHiddenFrom").serialize(),
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#payerDiv").html(data);
                    $("#payerDiv" ).dialog({  
                        title:'繳款人資料' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                    });
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                    $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                    $("#ajaxErrorMessageDiv" ).dialog({  
                        title:'系統錯誤' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                        , buttons: {
                            Ok: function() {
                                $( this ).dialog( "close" );
                            }
                        }
                    });
                },
            complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
        }); 
    }
    
    function doCheckAll(){
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){              
        $(this).attr("checked", true);
       });
	}
	
	function undoCheckAll(){
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){               
        $(this).attr("checked", false);
       });
	}
	
	function doPayersConfirmAction(paymentStatus)
	{
		var isDoComfirm = false;
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){               
        	if ( $(this).attr('checked') ){
        		isDoComfirm = true;
        	}
       	});
		
		if(isDoComfirm){
			$('#hidden\\.resultPayerTemp\\.payerStatus').val(paymentStatus);
			waitingDialog({});
			
			$.ajax({url : "<c:url value='/ajax/Soez2001.action'/>",
				async : true,
				type : 'POST',
				data : $("#confirmHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
						$("#ajaxErrorMessageDiv").html(data);
					},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){
					closeWaitingDialog();
				}
			});
	
		}else{
			$("#ajaxErrorMessageDiv").html("至少選擇一筆");
                    $("#ajaxErrorMessageDiv" ).dialog({  
                        title:'請修正下列錯誤' 
                        ,width: 300
                        , resizable: false
                        , modal: true
                        , buttons: {
                            Ok: function() {
                                $( this ).dialog( "close" );
                            }
                        }
                    });
                    return false;
		}
	}
	
    //-->
    </script>
</head>
<body>
<div id="mainAreaCT">
        <jsp:include page="/includes/path.jsp"/>
        <jsp:include page="/includes/subMenu.jsp"/>
        
    <div id="payerFormDiv">
        <stripes:form name="confirmHiddenFrom" id="confirmHiddenFrom" beanclass="com.feib.soeasy.action.Soez2001ActionBean" 
        method="post" onsubmit="javascript: return false;">
            
			<c:choose>
			    <c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">		        
			        
			            <table id="listTable">
			            <thead>
			                <tr>
			                    <th>&nbsp;</th>
			                    <th>序號</th>
			                    <%if ( UserUtil.isBankGroup()){ %>
								<th>業者代號</th>
								<th>業者名稱</th>
								<%} %>
			                    <th>客戶編號</th>
			                    <th>姓名</th>
			                    <th>手機</th>
			                    <th>E-MAIL</th>
			                    <th>交易紀錄狀態</th>
			                    <th>&nbsp;</th>
			                </tr>
			            </thead>
			            <tbody>
			                <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
			                <tr>
			                    <td>
			                    	<input name="checkPayerTemp[${rowstat.index}].payerTempPk" type="checkbox" id="checkPayerTemp[${rowstat.index}].payerTempPk" value="<c:out value='${viewObj.payerTempPk}'/>" class="chk"/>
			                    </td><td>	&nbsp;${rowstat.index+1 }
			                    </td>
			                    <%if ( UserUtil.isBankGroup()){ %>
								<td align="center"><c:out value="${viewObj.group.groupNo}" /></td>
								<td><c:out value="${viewObj.group.groupName}" /></td>
								<%} %>
			                    <td><c:out value="${viewObj.payerNo }"/></td>
			                    <td><c:out value="${viewObj.payerName }"/></td>
			                    <td><c:out value="${viewObj.payerCellNo }"/></td>
			                    <td><c:out value="${viewObj.payerEmail }"/></td>
			                 <c:choose>
			                  	<c:when test="${'D' == viewObj.recordStatus }"><td>刪除</td></c:when>
			                  	<c:when test="${'U' == viewObj.recordStatus }"><td>修改</td></c:when>
			                   	<c:otherwise><td>新增</td></c:otherwise>  
			                 </c:choose>  
			                    <td>
			                    	<div id="viewPayerImg-<c:out value='${viewObj.payerTempPk}'/>"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
			                    </td>               
			                </tr>
			                </c:forEach>
			            </tbody>
			        </table>
			        
			        <table width="100%">
						<tr>
							<td align="center">
								<stripes:hidden id="hidden.resultPayerTemp.payerStatus" name="resultPayerTemp.payerStatus"/>
								<input type="button" id="checkAll" name="checkAll" value="全選" />
								<input type="button" id="unCheckAll" name="unCheckAll" value="全不選" />
								<input type="button" id="passPayerBtn" name="passPayerBtn" value="放行" />
								<input type="button" id="cancelPayerBtn" name="cancelPayerBtn" value="退件" />
								<input type="button" id="printBtn2" value="列印" />	
								<input type="hidden" id="confirmMethod" name="doAjaxPayersConfirm"/>
							</td>
						</tr>
					</table>
			            
			        <script type="text/javascript">
			        <!--
			        $(document).ready(function() {
			            

		            	$('#printBtn2').click(function() {
		    				//window.print();
		    				//doQueryPrintAction();
		    				divPrint('payerFormDiv');//只印目前這筆
		    			});
		            	
			        });
			        //-->
			        </script>
			            
			    </c:when>
			    <c:otherwise>
			        <div id="queryNothingBlockDiv" style="display: none;">查無資料 </div>      
			        <script type="text/javascript">
			        <!--
			        $(document).ready(function() {
			            $( "#queryNothingBlockDiv" ).dialog({  
			                title:'<%=UserUtil.getCurrentMenuItemName() %>查詢' 
			                , width: 300
			                , resizable: false
			                , modal: true,
			                buttons : {
			                    Ok : function() {
			                        $(this).dialog("close");
			                    }
			                }  
			            });
			        });
			        //-->
			        </script>
			    </c:otherwise>
			</c:choose>            
        </stripes:form>
    </div>
    
    <!-- 繳款人明細查詢 -->
    <div id="payerDiv" style="display: none;">
    </div>
    <div id="queryPayerTempHiddenFormDiv" style="display: none; ">
        <stripes:form id="queryPayerTempHiddenFrom" beanclass="com.feib.soeasy.action.Soez2001ActionBean" 
            method="post" onsubmit="javascript: return false;">         
            <stripes:hidden id="hidden.payerTempPk" name="payerTempPk"/>       
            <input type="hidden" id="method2" name="doAjaxQueryPayer"/>
        </stripes:form>
    </div> 
        
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>

</div>                
</body>
</html>    